#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
bool isPalindrome(struct ListNode* head) {
    struct ListNode* slow = head;
    struct ListNode* fast = head;

    if (head->next == NULL)
        return true;

    while (fast && fast->next)
    {
        fast = fast->next->next;
        slow = slow->next;
    }

    //slow->next = NULL;
    struct ListNode* fro = slow;
    struct ListNode* late = slow->next;
    struct ListNode* a = NULL;
    fro->next = NULL;
    while (late)
    {
        a = late->next;
        late->next = fro;
        fro = late;
        late = a;
        if (a != NULL)
            a = a->next;
    }
    a = fro;
    while (head != slow)
    {
        if (head->val != a->val)
            return false;
        a = a->next;
        head = head->next;
    }



    return true;
}